package com.mentalhealthplatform.studentV3.dto;

import com.mentalhealthplatform.appModels.Student;
import com.mentalhealthplatform.global.rbac.dto.normal.RoleDTO;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.Date;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;

/**
 * @author Pear
 */
@Getter
@Setter
@NoArgsConstructor
public class StudentDTOV3 extends UserDTOV3 {
    private String address;
    private Date birthDate;
    private String name;
    private String number;
    private String gender;
    private String major;
    private String grade;
    private String college;

    // 全参构造方法
    public StudentDTOV3(UUID id, String username, boolean status, String address, Date birthDate, String name,
                        String number, String gender, String major, String grade, String college, Set<RoleDTO> roles) {
        super(id, username, status, roles);
        this.address = address;
        this.birthDate = birthDate;
        this.name = name;
        this.number = number;
        this.gender = gender;
        this.major = major;
        this.grade = grade;
        this.college = college;
    }

    // 实体到 DTO 的转换方法
    public static StudentDTOV3 convertToDTO(Student student) {
        Set<RoleDTO> roleDTOs = student.getRoles().stream()
                .map(RoleDTO::convertToDTO)
                .collect(Collectors.toSet());

        return new StudentDTOV3(
                student.getId(),
                student.getUsername(),
                student.isStatus(),
                student.getAddress(),
                student.getBirthDate(),
                student.getName(),
                student.getNumber(),
                student.getGender(),
                student.getMajor(),
                student.getGrade(),
                student.getCollege(),
                roleDTOs
        );
    }
}
